package main

import (
	"net/http"
	"fmt"
	router "git.oschina.net/Ljohn/Base/controllers"
	myPort "git.oschina.net/Ljohn/Base/conf/port"
)

func main(){
	mux :=http.NewServeMux()
	mux.HandleFunc("/api/test",router.Test)
	fmt.Println("start ....")
	err:=http.ListenAndServe(myPort.OpenPort(),middleWare(mux))
	if err!=nil{
		fmt.Println("启动程序失败  ：  ",err.Error())
	}
	fmt.Println("start .....")
}
func middleWare(x http.Handler)http.Handler{
	return http.HandlerFunc(func(w http.ResponseWriter,req *http.Request){
		w.Header().Set("Access-Control-Allow-Origin", "*")
		w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Headers, Authorization, Authorization-Token")
		w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE")
		w.Header().Set("Content-Type", "application/json")
		x.ServeHTTP(w,req)
	})
}
